#define _CRT_SECURE_NO_DEPRECATE
#include "input_data.h"
#include <cstring>

void input_data::create_logfile(){
  char logname[100];
  char sgn = (beta.p == 0) ? '-' : '+';
  sprintf(logname, "a%dr%db%d%d%c%s.log", ALPH_SIZE, ROOT_LENGTH, beta.num, beta.denum, sgn, 
    (power_type == 0) ? "weak" : (power_type == 1) ? "moder" : "strong");
  logfile = fopen(logname, "w");
}

void input_data::dump_input() const{
  dump("Calculating answer for test:\n");
  char sgn = (beta.p == 0) ? '-' : '+';
  dump("Alphabet size = %d, Root length <= %d\nExponent = %d/%d%c", ALPH_SIZE, ROOT_LENGTH, beta.num, beta.denum, sgn);
  char type[20];
  if (power_type == WEAK) strcpy(type, "WEAK");
  else if (power_type == MODERATE) strcpy(type, "MODERATE");
  else strcpy(type, "STRONG");
  dump("%s", type);
  dump("\nPrecision = %.20lf\n\n", delta);
}

void input_data::dump(const char *str, ...) const{
  va_list args;
  va_start(args, str);
  vfprintf(logfile, str, args);
  fflush(logfile);
  va_end(args);
}
